package chapter5.section3;

//程序5-4：一个添加了方法的类
public class Account0504 {
    private final String id;
    private final String name;
    private int balance;

    public Account0504(String id, String name, int balance) {
        super();
        this.id = id;
        this.name = name;
        this.balance = balance;
    }

    // 一个存款方法，将存款额增加到余额上
    public void deposit(int amount) {
        this.balance += amount;
        saveToDB();
    }

    // 一个取款方法，将存款额从余额减去
    public void withdraw(int amount) {
        this.balance -= amount;
        saveToDB();
    }

    // 返回一个账户的当前余额
    public int getBalance() {
        return this.balance;
    }

    private void saveToDB() {
        // 省略保存操作到数据库的代码
    }

    public static void main(String[] args) {
        Account0504 a = new Account0504("001", "鲁宁", 1000);
        a.withdraw(100);
        a.deposit(150);
        System.out.println(a.getBalance());
    }
}
